//
//  GHOffLineRechargeController.m
//  GodHorses
//
//  Created by Mac on 2017/11/22.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "GHOffLineRechargeController.h"
#import "STTextView.h"
@interface GHOffLineRechargeController ()
@property(nonatomic, strong) UITextField                     *nameTaxtefiled;
@property(nonatomic, strong) UITextField                     *phoneTaxtefiled;
@property(nonatomic, strong) UITextField                     *moneyTaxtefiled;
@property(nonatomic, strong) STTextView                     *textView;
@end

@implementation GHOffLineRechargeController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"线下充值";
    [self configSubView];
    [self configFooterView];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubView{
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 200)];
    headerView.backgroundColor = self.tableView.backgroundColor;
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 30)
                                                     text:@"转账人姓名"
                                                textColor:GH_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:titleLable];
    
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, titleLable.bottom, UIScreenWidth, 35)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:whiteView];
    
    self.nameTaxtefiled = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 35)];
    self.nameTaxtefiled.textColor = GH_firstTextColor;
    self.nameTaxtefiled.font = [UIFont systemFontOfSize:15];
    self.nameTaxtefiled.placeholder = @"请输入姓名";
    [whiteView addSubview:self.nameTaxtefiled];
    
    STLabel * contactLable = [[STLabel alloc] initWithFrame:CGRectMake(10, whiteView.bottom, UIScreenWidth - 20, 30)
                                                     text:@"转账人联系方式"
                                                textColor:GH_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:contactLable];
    
    UIView * contactwhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, contactLable.bottom, UIScreenWidth, 35)];
    contactwhiteView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:contactwhiteView];
    
    self.phoneTaxtefiled = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 35)];
    self.phoneTaxtefiled.placeholder = @"请输入联系方式";
    self.phoneTaxtefiled.textColor = GH_firstTextColor;
    self.phoneTaxtefiled.keyboardType = UIKeyboardTypeNumberPad;
    [contactwhiteView addSubview:self.phoneTaxtefiled];
  
    STLabel * moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(10, contactwhiteView.bottom, UIScreenWidth - 20, 30)
                                                     text:@"转账金额"
                                                textColor:GH_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:moneyLable];
    
    UIView * moneywhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, moneyLable.bottom, UIScreenWidth, 35)];
    moneywhiteView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:moneywhiteView];
    
    self.moneyTaxtefiled = [[UITextField alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 35)];
    self.moneyTaxtefiled.placeholder = @"请输入金额";
    self.moneyTaxtefiled.textColor = GH_firstTextColor;
    self.moneyTaxtefiled.keyboardType = UIKeyboardTypeNumberPad;
    [moneywhiteView addSubview:self.moneyTaxtefiled];
    
    STLabel * textLable = [[STLabel alloc] initWithFrame:CGRectMake(10, moneywhiteView.bottom, UIScreenWidth - 20, 30)
                                                     text:@"转账备注"
                                                textColor:GH_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:textLable];
    UIView * textwhiteView = [[UIView alloc] initWithFrame:CGRectMake(0, textLable.bottom , UIScreenWidth, 200)];
    textwhiteView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:textwhiteView];
    
    self.textView = [[STTextView alloc] initWithFrame:CGRectMake(10, 0, UIScreenWidth - 20, 35)];
    self.textView.placeholder = @"请输入转账备注";
    self.textView.textColor = GH_firstTextColor;
    [textwhiteView addSubview:self.textView];
    
    headerView.height = textwhiteView.bottom + 10;
    self.tableView.tableHeaderView = headerView;
}
- (void)configFooterView{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, 0, UIScreenWidth - 60, 44)
                                                        title:@"提交"
                                                   titleColor:GH_YellowBackGroundColor
                                                    titleFont:18
                                                 cornerRadius:5
                                              backgroundColor:GH_BlackBackGroundColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedCommitButton];
    }];
    confimButton.st_centerY = 50;
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelectedCommitButton{
    if (!self.nameTaxtefiled.text.length) {
        [SVProgressHUD showErrorWithStatus:@"请输入姓名"];
        return;
    }
    if (!self.phoneTaxtefiled.text.length) {
        [SVProgressHUD showErrorWithStatus:@"请输入联系方式"];
        return;
    }
    if (!self.moneyTaxtefiled.text.length) {
        [SVProgressHUD showErrorWithStatus:@"请输入转账金额"];
        return;
    }
    if (!self.textView.text.length) {
        [SVProgressHUD showErrorWithStatus:@"请输入转账备注"];
        return;
    }
    [self sendOffLineRechargeRequest];
}
#pragma mark --NetWork Method
- (void)sendOffLineRechargeRequest{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    if ([GHUserManger defult].userID.length) {
        [dic setObject:[GHUserManger defult].userID forKey:@"uid"];
    }
    if ([GHUserManger defult].token.length) {
        [dic setObject:[GHUserManger defult].token forKey:@"token"];
    }
    if (self.nameTaxtefiled.text.length) {
         [dic setObject:self.nameTaxtefiled.text forKey:@"name"];
    }
    if (self.phoneTaxtefiled.text.length) {
         [dic setObject:self.phoneTaxtefiled.text forKey:@"contact"];
    }
    if (self.moneyTaxtefiled.text.length) {
        [dic setObject:self.moneyTaxtefiled.text forKey:@"money"];
    }
    if (self.textView.text.length) {
        [dic setObject:self.textView.text forKey:@"saymore"];
    }
    [[STNetWrokManger defaultClient] requestWithPath:@"http://test.smqyp.com/Api/cash/line_down_recharge"
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showSuccessWithStatus:@"已成功提交线下充值申请"];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
@end
